package cqie.frame.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
@ApiModel(value = "ResultJson对象",description = "Api返回的结构")
public class    ResultJson<T> {
    //状态码
    @ApiModelProperty(value = "状态码")
    private int code;
    //提示信息
    @ApiModelProperty(value = "提示信息")
    private String msg;
    //返回的数据
    @ApiModelProperty(value = "返回的数据")
    private T data;

    public static <T> ResultJson<T> success(T data) {
        return new ResultJson<T>(data);
    }

    public static <T> ResultJson<T> error(CodeMsg codeMsg) {
        return new ResultJson<T>(codeMsg);
    }

    private ResultJson(T data) {
        this.code = 0;
        this.msg = "success";
        this.data = data;
    }

    private ResultJson(CodeMsg codeMsg) {
        if (codeMsg == null) {
            return;
        }
        this.code = codeMsg.getCode();
        this.msg = codeMsg.getMsg();
    }
}